package com.zat.mes.andrmes.dofun.work.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.love.zywanandroid.retrofit.RetrofitManager
import com.love.zywanandroid.retrofit.api.ApiService
import com.tencent.bugly.proguard.s
import com.zat.mes.andrmes.data.*
import com.zat.mes.andrmes.retrofit.callback.MesCallBack
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.Response

/**
 * @author zy
 * @date :2020-09-12 13:59
 * @description: 废片 拆解单 model
 */
class BadFlatModel:ViewModel() {

    private val badFlat: MutableLiveData<String> = MutableLiveData()
    private val scheduClass:MutableLiveData<MutableList<ScheduClassBean>> = MutableLiveData()
    private val scheduEmp:MutableLiveData<MutableList<ScheduClassBean>> = MutableLiveData()
    fun getBadFlat(): LiveData<String> {
        return badFlat
    }

    fun getScheduClass():LiveData<MutableList<ScheduClassBean>>{
        return scheduClass
    }

    fun getScheduEmp():LiveData<MutableList<ScheduClassBean>>{
        return scheduEmp
    }
    /**
     * 新增废片
     */
    fun postBadFlat(json:String){
        val requestBody: RequestBody = RequestBody.create(RetrofitManager.JOSNTYPE, json)
        RetrofitManager.apiService(ApiService::class.java)
            .postBadFlat(requestBody)
            .enqueue(object :MesCallBack<BaseResponse<String>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<String>>?,
                    response: Response<BaseResponse<String>>?
                ) {
                    badFlat.postValue(response?.body()?.message)
                }

            })
    }
    /**
     * 新增废片
     */
    fun postDisasse(json:String){
        val requestBody: RequestBody = RequestBody.create(RetrofitManager.JOSNTYPE, json)
        RetrofitManager.apiService(ApiService::class.java)
            .postDissasse(requestBody)
            .enqueue(object :MesCallBack<BaseResponse<String>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<String>>?,
                    response: Response<BaseResponse<String>>?
                ) {
                    badFlat.postValue(response?.body()?.message)
                }

            })
    }

    /**
     * 查询排班下的班组
     */

    fun getScheduClass(scheduId:Long?){
        RetrofitManager.apiService(ApiService::class.java)
            .getScheduClass(scheduId)
            .enqueue(object :MesCallBack<BaseResponse<MutableList<ScheduClassBean>>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<MutableList<ScheduClassBean>>>?,
                    response: Response<BaseResponse<MutableList<ScheduClassBean>>>?
                ) {
                    scheduClass.postValue(response?.body()?.result as MutableList<ScheduClassBean>)
                }

            })
    }

    /**
     * 查询排班下的班组的人员
     */

    fun getScheduEmp(scheduId:Long?,classId:Long){
        RetrofitManager.apiService(ApiService::class.java)
            .getScheduEmp(scheduId,classId)
            .enqueue(object :MesCallBack<BaseResponse<MutableList<ScheduClassBean>>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<MutableList<ScheduClassBean>>>?,
                    response: Response<BaseResponse<MutableList<ScheduClassBean>>>?
                ) {
                    scheduEmp.postValue(response?.body()?.result as MutableList<ScheduClassBean>)
                }

            })
    }



}